package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityInNote;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * Created by zlz
 * on  4/18/21
 */
public class VMInNote extends ViewModel {

    private MutableLiveData<List<EntityInNote>> liveInNote = new MutableLiveData<>();

    public MutableLiveData<List<EntityInNote>> getLiveInNote() {
        return liveInNote;
    }

    public void requestData(){


        Observable.timer(3, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {


                        liveInNote.setValue(createTestData());
                    }
                });



    }


//<editor-fold defaultState="collapsed" desc="测试">


    private List<EntityInNote> createTestData(){

        List<EntityInNote> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {

            EntityInNote entityInNote = new EntityInNote();

            entityInNote.setNum("1");
            entityInNote.setPrice("3");
            entityInNote.setSize("2");
            entityInNote.setTotal("22");
            entityInNote.setTime("2020-12-31-19:04");


            list.add(entityInNote);

        }

        return  list;
    }

// </editor-fold>

}
